package model;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Class for user's creation in the system.
 * The user can be an administer, operator or a simple player in the leagues
 * 
 * The required attributes are:
 * Name (first and last), email, password.
 * The others main attributes are:
 * Phones (home, work and cell), picture and handicap.  
 * 
 * @author Andre Melo
 * @author Marcus Leite 
 * @author Sergio Danilo
 *
 */
@Entity
@Table(name="USERS")
public class User {
	
	//Attributes
	public static final String ROLE_ADMIN = "ADMIN";
	
	public static final String ROLE_OPERATOR = "OPERATOR";
	
	public static final String ROLE_PLAYER = "PLAYER";
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer id;
	
	@Column(name="FIRST_NAME", nullable=false)
	private String firstName;
	
	@Column(name="LAST_NAME", nullable=false)
	private String lastName;
	
	@Column(name="HOME_PHONE", nullable=true)
	private String homePhone;
	
	@Column(name="WORK_PHONE", nullable=true)
	private String workPhone;
	
	@Column(name="CELL_PHONE", nullable=true)
	private String cellPhone;
	
	@Column(name="EMAIL", nullable=false, unique=true)
	private String email;
	
	@Column(name="PICTURE", nullable=true)
	private String picture;
	
	@Column(name="HANDICAP", nullable=false)
	private Integer handicap = 200;
	
	@Column(name="PASSWORD", nullable=false)
	private String password;
	
	@Column(name="ROLE", nullable=false)
	private String role;
			
	/**
	 * An user's constructor
	 */
	public User() {}
	
	/**
	 * An user's constructor with received parameteres
	 * 
	 * @param firstName The fist name of the user
	 * @param lastName The last name of the user
	 * @param homePhone The home phone of the user
	 * @param workPhone The work phone of the user
	 * @param cellPhone The cell phone of the user
	 * @param email The email of the user
	 * @param picture The picture of the user
	 * @param password The password of the user
	 */
	//por enquanto esse serve pra o jsp
	public User(String firstName, String lastName, String homePhone,
			String workPhone, String cellPhone, String email, String picture, String password) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.homePhone = homePhone;
		this.workPhone = workPhone;
		this.cellPhone = cellPhone;
		this.email = email;
		this.picture = picture;
		this.password = password;
	}

	/**
	 * An user's constructor with received parameteres
	 * 
	 * @param firstName The fist name of the user
	 * @param lastName The last name of the user
	 * @param homePhone The home phone of the user
	 * @param workPhone The work phone of the user
	 * @param cellPhone The cell phone of the user
	 * @param email The email of the user
	 * @param picture The picture of the user
	 * @param password The password of the user
	 * @param roles The roles of the user
	 */
	public User(String firstName, String lastName, String homePhone,String workPhone, String cellPhone,
			    String email, String picture, String password, String role) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.homePhone = homePhone;
		this.workPhone = workPhone;
		this.cellPhone = cellPhone;
		this.email = email;
		this.picture = picture;
		this.password = password;
		this.role = role;
	}
	
	/**
	 * Get the cell phone of the user.
	 * @return Cell phone of the user.
	 */
	public String getCellPhone() {
		return cellPhone;
	}
	
	/**
	 * Get the e-mail of the user.
	 * @return E-mail of the user.
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Get the first name of the user.
	 * @return First name of the user.
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Get the user's handicap
	 * @return The user's handicap
	 */
	public Integer getHandicap() {
		return handicap;
	}

	/**
	 * Get the home phone of the user.
	 * @return Home phone of the user.
	 */
	public String getHomePhone() {
		return homePhone;
	}

	/**
	 * Get the user's Id.
	 * @return The user's Id.
	 */
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Get the last name of the user.
	 * @return The last name of the user.
	  */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Get the password of the user
	 * @return The password of the user
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Get the picture archive name of the user.
	 * @return The picture archive name of the user.
	 */
	public String getPicture() {
		return picture;
	}

	/**
	 * Get the roles of the user
	 * @return The roles
	 */
	public String getRole() {
		return role;
	}

	/**
	 * Get the work phone of the user.
	 * @return Work phone of the user.
	 */
	public String getWorkPhone() {
		return workPhone;
	}

	/**
	 * Set the cell phone of the user.
	 * @param cellPhone
	 */
	public void setCellPhone(String cellPhone) {
		this.cellPhone = cellPhone;
	}

	/**
	 * Set the e-mail of the user.
	 * @param email E-mail of the user.
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Set the first name of the user.
	 * @param firstName First name of the user.
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	/**
	 * Set the user's handicap 
	 * @param handicap The handicap value
	 */
	public void setHandicap(Integer handicap) {
		this.handicap = handicap;
	}
	
	/**
	 * Set the home phone of the user.
	 * @param homePhone Home phone of the user.
	 */
	public void setHomePhone(String homePhone) {
		this.homePhone = homePhone;
	}
	
	/**
	 * Set the last name of the user.
	 * @param lastName Last name of the user.
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Set the password of the user
	 * @param password The new password of the user
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * Set the picture archive name of the user.
	 * @param picture Name of the picture archive.
	 */
	public void setPicture(String picture) {
		this.picture = picture;
	}

	/**
	 * Set the roles of the user
	 * @param roles The new roles of user
	 */
	public void setRole(String role) {
		this.role = role;
	}

	/**
	 * Set the work phone of the user.
	 * @param workPhone Work phone of the user.
	 */
	public void setWorkPhone(String workPhone) {
		this.workPhone = workPhone;
	}

	/**
	 * Return true if the user is an operator, false otherwise
	 * @return true if the user is an operator, false otherwise
	 */
	public boolean isOperator() {
		return getRole().equals(ROLE_OPERATOR);
	}

	/**
	 * Set the user as operator
	 */
	public void setOperator() {
		this.role = ROLE_OPERATOR;
	}
	
	/**
	 * Set if the user was not a league operator.
	 */
	public void setNotOperator(){
		this.role = ROLE_PLAYER;
	}
}